﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fcdbas.Core.Services
{
    /// <summary>
    /// 消息系统服务总线
    /// </summary>
    public interface IServiceBus
    {
        /// <summary>
        /// 注册消息处理回调函数
        /// </summary>
        /// <typeparam name="TCommand">消息类型</typeparam>
        /// <param name="handler">回调函数</param>
        void RegisterMessageHandler<TCommand>(Action<TCommand> handler) where TCommand : class;
        /// <summary>
        /// 注册消息的终结点
        /// </summary>
        /// <typeparam name="TCommand"></typeparam>
        /// <param name="targetEndpoint">终结点标识符@目标地址</param>
        void RegisterMessageEndpoint<TCommand>(string targetEndpoint) where TCommand : class;
        /// <summary>
        /// 注册发布者
        /// </summary>
        /// <typeparam name="TEvent"></typeparam>
        void HandleSubscriptionsFor<TEvent>() where TEvent : class;
        /// <summary>
        /// 发送对象
        /// </summary>
        /// <param name="command"></param>
        void Send(object command);
        /// <summary>
        /// 接收回复消息
        /// 跟Send配对使用
        /// </summary>
        /// <param name="message"></param>
        /// <param name="response"></param>
        void Reply(object message, object response);
        /// <summary>
        /// 发布消息
        /// </summary>
        /// <param name="event">消息内容</param>
        void Publish(object @event);

        /// <summary>
        /// 订阅消息
        /// </summary>
        /// <typeparam name="TEvent">消息类型</typeparam>
        /// <param name="publisherEndpoint">消息终接点</param>
        /// <param name="handler">回调处理</param>
        void Subscribe<TEvent>(string publisherEndpoint, Action<TEvent> handler) where TEvent : class;
        /// <summary>
        /// 取消订阅
        /// </summary>
        /// <typeparam name="TEvent"></typeparam>
        /// <param name="publisherEndpoint">消息终接点</param>
        void UnSubscribe<TEvent>(string publisherEndpoint) where TEvent : class;
        /// <summary>
        /// 启动处理
        /// </summary>
        void Start();
        /// <summary>
        /// 停止
        /// </summary>
        void Stop();
        /// <summary>
        /// 终接点
        /// </summary>
        string LocalEndpoint { get; set; }
    }
}
